#!/usr/bin/env python
# coding: utf-8
# @File : studyPython.PY
# @Autor: FY
# @Date: 2021/8/23
import datetime

dict_A = {'en':'英语', 'cn':'中文', 'fr':'法语', 'jp':'日语'}
print(dict_A)

list_keys = dict_A.keys()
print(list_keys)
list_values = dict_A.values()
print(list_values)

print(zip(list_keys, list_values))

dict_B = dict(zip(list_keys, list_values))
print(dict_B)

list_B = list(zip(list_keys, list_values))
print(list_B)

list_m = ['a', 'b']
list_c = list(zip(list_keys, list_values, list_m))
print(list_c)

list_d,list_e, list_f = zip(*zip(list_keys, list_values, list_m))
print(list_d)
print(list_e)
print(list_f)

# 以下是面试题
print(1 and False or 2)


def square(x):
    return x**2

print(map(square, [1,2,3,4,5]))
print(list(map(square, [1,2,3,4,5])))

print(list(map(lambda x: x**2, [1,2,3,4,5])))


# 去除重复的元素
a = [1, 4, 4, 4, 5, 3, 3, 2]
def set_duplicate_remove(list_a):
    list_b = set(list_a)
    print(list_b)
    print(list(list_b))

set_duplicate_remove(a)


lst = [[0, 1,2],[2,2,2],[2,3,2]]
lst1 = [[0, 1,2],[2,2,2],[2,2,5]]
lst2 = []


print("lst2")

for i in range(3):
    lst2.append([])
    for j in range(3):
        a = lst[i][j]*lst1[i][j]
        print(a)
        lst2[i].append(a)

print(lst2)


def log(func):
    def warpper(*args, **kwargs):
        print("call %s()"%func.__name__)
        return func(*args, **kwargs)
    return warpper

@log
def now():
    print(datetime.datetime.now())

now()


def deduplication(self, nums):
    for i in range(len(nums)):
        if nums[i] == self:
            return i
    i = 0
    for x in   nums:
        if self > x:
            i +=1
    return i

print(deduplication(5, [1, 3, 5,6]))

# 两个字符串s和，判断t是否是s的重新排列后组成的单词

string_A = "Hello world"

def IsSortedString(string_A, string_B):
    list_A = list(string_A)
    sorted_A = sorted(list_A)
    # return  sorted_A == list(string_B)
    print("".join(sorted_A))
    return "".join(sorted_A) == string_B

print(IsSortedString(string_A, " Hdellloorw"))


# 利用二分法，快速找出某个值在数列中的位置，并给出时间复杂度，并说明原因

def lgfind(list_A, ele_B):
        # 以下是二分法查找方法，二分法查找是有顺序的
    sorted_A = sorted(list_A)
    start_index = 0
    end_index = len(list_A)
    while start_index < end_index - start_index -1:
        mid_index = (end_index - start_index)//2
        if sorted_A[mid_index] < ele_B:
            start_index = mid_index + 1
        elif sorted_A[mid_index] == ele_B:
            return ele_B
        elif sorted_A[mid_index] > ele_B:
            end_index = mid_index

        return mid_index
mylist = [20,50,22,-22,0,15,222,28,29,99,1999,100823,55,35,5,1,2,3,8,9,55,10239,234234]
print(lgfind(mylist, 28))